YouTube shortcode fix for a blog imported from WordPress.com
로빈아빠
본문
- [youtube=http://www.youtube.com/watch?v=1LLls4hPEfM&w=500&h=311]
This is actually pretty easy to fix once your figure out the regular expression that can grab the YouTube video id, width and height from the shortcode. Then you add a shortcode definition to the functions.php file of your theme by copying and pasting this code:
- function youtubeSC($atts) {
- $posttext = substr($atts[0],1);
- preg_match('/v\=([a-zA-Z0-9]+)/', $posttext, $youtubeID);
- preg_match('/w\=([0-9]+)/', $posttext, $width);
- preg_match('/h\=([0-9]+)/', $posttext, $height);
- return '<iframe width="' . $width[1] . '" height="' . $height[1] . '" src="http://www.youtube.com/embed/' . $youtubeID[1] . '" frameborder="0" allowfullscreen></iframe>';
- }
Hope that helps!
관련링크
댓글목록
등록된 댓글이 없습니다.